<%--
    Document   : cliente
    Created on : 08/10/2010, 17:42:00
    Author     : renan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>

<f:view>
    <h:form id="LSUsuario">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <link rel="stylesheet" type="text/css" href="../../css/style.css">
                <script type="text/javascript" src="../../js/funcoes.js"></script>
                <style type="text/css">
                    .acao {
                        width: 20%;
                        text-align: center;
                    }
                    .nome {
                        width: 35%;
                        text-align: left;
                    }
                    .login{
                        width: 15%;
                        text-align: left;
                    }
                    .nivel{
                        width: 20%;
                        text-align: left;
                    }
                    .situacao{
                        width: 10%;
                        text-align: left;
                    }
                </style>
                <title>Cadastro de Usuários</title>
            </head>
            <body onload="foco();">
                <!--  BOTÕES PADRÔES  -->
                <table width="100%">
                    <tr>
                        <td align="left">
                            <h:commandButton id="btInserir"  image="../../imagens/inserir.png" action="#{usuarioFrm.cadastrar}"
                                             title="Inserir novo registro" onmouseover="mouseSobre(this);" onmouseout="mouseSai(this);"
                                             onmousedown="mouseClicou(this);" onmouseup="mouseDesclicou(this);"/>
                            <a4j:status>
                                <f:facet name="start">
                                    <h:graphicImage value="../../imagens/ajax-loader.gif"/>
                                </f:facet>
                            </a4j:status>
                        </td>
                        <td align="right">
                            <input type="image" src="../../imagens/sair.png" onclick="window.close(); return false"
                                   title="Fechar" onmouseover="mouseSobre(this);" onmouseout="mouseSai(this);"
                                   onmousedown="mouseClicou(this);" onmouseup="mouseDesclicou(this);" >
                        </td>
                    </tr>
                </table>
                <table width="100%">
                    <tr>
                        <td>
                            <rich:panel id="painelLista">
                                <f:facet name="header">
                                    <h:outputText value="Manutenção de Usuários"></h:outputText>
                                </f:facet>
                                <h:panelGrid columns="1" styleClass="rotulo">

                                    <!-- FILTRO LISTA -->
                                    <table width="100%">
                                        <tr>
                                            <td>
                                                <fieldset><legend>Pesquisar</legend>
                                                    <table width="567px">
                                                        <tr>
                                                            <td align="left" class="rotulo">
                                                                Login:
                                                            </td>
                                                            <td>
                                                                <h:inputText id="descricao" onkeydown="mascara(this,maiusculo);" value="#{usuarioFrm.login}" size="40" styleClass="campo"
                                                                             onfocus="ganhouFoco(this);" onblur="perdeuFoco(this);"/>
                                                            </td>
                                                            <td>
                                                                <a4j:commandButton id="btPesquisar" value="Pesquisar" action="#{usuarioFrm.pesquisar}"
                                                                                   reRender="tabela,erros" title="Pesquisar Registros"
                                                                                   styleClass="campo"/>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </fieldset>
                                            </td>
                                        </tr>
                                    </table>
                                </h:panelGrid>
                            </rich:panel>
                        </td>
                    </tr>
                </table>
                <!-- LISTA DE DADOS -->
                <table width="100%">
                    <tr>
                        <td>
                            <div class="divTabela" style="height: 250px;">
                                <rich:dataTable id="tabela" cellspacing="1" width="96%" styleClass="margin:0px;"
                                                columnClasses="acao,nome,login,nivel,situacao" value="#{usuarioFrm.colecao}" var="item"
                                                onRowMouseOver="focoLinha(this);" onRowMouseOut="desfocoLinha(this);">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText styleClass="rotuloGrid" value="AÇÃO"/>
                                        </f:facet>
                                        <%-- BOTÕES DA GRID --%>
                                        <h:commandButton title="Alterar o registro" action="#{usuarioFrm.alterar}" image="../../imagens/lsAlterar.png"/>
                                        <f:verbatim>&nbsp;</f:verbatim>
                                        <a4j:commandButton title="Deletar o registro" action="#{usuarioFrm.remover}" image="../../imagens/lsExcluir.png" onclick="if(!window.confirm('Confirma exclusão de registro?')){foco();return false;}" reRender="tabela,erros"/>
                                        <f:verbatim>&nbsp;</f:verbatim>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <a4j:commandLink action="#{usuarioFrm.ordenarPorColuna}" actionListener="#{usuarioFrm.setarColuna}" reRender="tabela" oncomplete="foco();">
                                                <a4j:actionparam name="coluna" value="nome"/>
                                                <h:outputText value="NOME"/>
                                            </a4j:commandLink>
                                        </f:facet>
                                        <h:outputText value="#{item.usuario.nome}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <a4j:commandLink action="#{usuarioFrm.ordenarPorColuna}" actionListener="#{usuarioFrm.setarColuna}" reRender="tabela" oncomplete="foco();">
                                                <a4j:actionparam name="coluna" value="login"/>
                                                <h:outputText value="LOGIN"/>
                                            </a4j:commandLink>
                                        </f:facet>
                                        <h:outputText value="#{item.usuario.login}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <a4j:commandLink action="#{usuarioFrm.ordenarPorColuna}" actionListener="#{usuarioFrm.setarColuna}" reRender="tabela" oncomplete="foco();">
                                                <a4j:actionparam name="coluna" value="nivel"/>
                                                <h:outputText value="NÍVEL"/>
                                            </a4j:commandLink>
                                        </f:facet>
                                        <h:outputText value="#{item.usuario.nivel == '1' ? 'ADMINISTRADOR' :
                                                               item.usuario.nivel == '2' ? 'GERENTE':
                                                               item.usuario.nivel == '3'? 'CLIENTE' : ''}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <a4j:commandLink action="#{usuarioFrm.ordenarPorColuna}" actionListener="#{usuarioFrm.setarColuna}" reRender="tabela" oncomplete="foco();">
                                                <a4j:actionparam name="coluna" value="situacao"/>
                                                <h:outputText value="SITUAÇÃO"/>
                                            </a4j:commandLink>
                                        </f:facet>
                                        <h:outputText value="#{item.usuario.situacao == '1' ? 'ATIVO': 'INATIVO'}"/>
                                    </h:column>
                                </rich:dataTable>
                            </div>
                        </td>
                    </tr>
                </table>
                <!-- AREA DE MENSAGENS -->
                <table width="100%">
                    <tr>
                        <td>
                            <fieldset>
                                <h:panelGroup id="erros">
                                    <rich:messages globalOnly="true" layout="table" styleClass="textoErro">
                                        <f:facet name="errorMarker">
                                            <h:graphicImage value="../../imagens/important.png"/>
                                        </f:facet>
                                    </rich:messages>
                                </h:panelGroup>
                            </fieldset>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </h:form>
    <script type="text/javascript">
        function foco() {
            el('LSUsuario:btInserir').focus();
        }
    </script>
</f:view>

